package com.yu.subject.domain.handler.subject;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yu.subject.common.enums.SubjectInfoTypeEnum;
import com.yu.subject.domain.entity.SubjectAnswerBO;
import com.yu.subject.domain.entity.SubjectInfoBO;
import com.yu.subject.domain.entity.SubjectOptionBO;
import com.yu.subject.infra.basic.entity.SubjectBrief;
import com.yu.subject.infra.basic.entity.SubjectJudge;
import com.yu.subject.infra.basic.service.SubjectBriefService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 路亚
 * @version 0.1
 * @className RadioTypeHandler
 * @description
 * @date 2024/12/24 22:32
 * @since jdk11
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        // 插入
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Integer subjectId) {
        QueryWrapper<SubjectBrief> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("subject_id", subjectId);
        List<SubjectBrief> subjectBrief = subjectBriefService.list(queryWrapper);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.get(0).getSubjectAnswer());
        return subjectOptionBO;
    }
}
